package org.netty.client.controller;

import org.netty.client.config.NettyClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.netty.channel.Channel;
import jakarta.annotation.Resource;

@RestController
@RequestMapping(value = "/clientserver", method = RequestMethod.GET)
public class NettyClientController {

    @Resource
    private NettyClient clientServer;

    @RequestMapping("/sendMessage")
    public String sendMessage() {
    	Channel channel = clientServer.getChannel();
    	// 测试粘包
    	String str = "你好，SpringBoot启动的netty服务端, ";
    	for (int i = 0; i < 5000; i++) {
    		str += "测试粘包, ";
		}
    	str += "“我的结尾是一个换行符，用于传输半包粘包处理”\r\n";
    	channel.writeAndFlush(str);
    	return "test start";
    }
}
